package app.yj.channel.http;

import android.support.annotation.NonNull;

import com.orhanobut.logger.Logger;

import app.yj.channel.Config;
import app.yj.channel.entity.BlogResult;
import app.yj.channel.strategy.BlogStrategy;
import app.yj.channel.util.BlogUtil;


/**
 * Anthor:NiceWind
 * Time:2019/4/12
 * Desc:The ladder is real, only the climb is all.
 */
public class HttpBlog {

    public static void requestTableSwitch(final String link, final String type, @NonNull final IBlogCallback blogCallback, final BlogStrategy strategy) {

//        Logger.e("---HttpBlog---link:" + link + "\ttype:" + type);
//Config.BLOG_KEY
        BlogUtil.getCheckVersion(link, Config.BLOG_KEY, new BlogUtil.OnResultListener() {
            @Override
            public void onResult(final BlogResult result, final Exception e) {
                boolean isSuccess = result != null;
                strategy.setHttpBlog(type, new BlogStrategy.HttpResult(type, isSuccess, new BlogStrategy.IResultCallBack() {
                    @Override
                    public void doCallback() {
                        blogCallback.newRequest(result);
                    }
                }));
            }
        });
    }

    /**
     * 用于请求成功后重新回调发起请求
     */
    public interface IBlogCallback {
        //重新请求
        void newRequest(BlogResult blogResult);
    }
}